﻿package export.huodong.scoreShop
{
	import com.dusk.util.ResUtil;
	import com.dusk.util.TextUtil;
	import com.game.data.constant.ConfigConst;
	import com.game.data.vo.PetDataVO;
	import com.game.data.vo.PlayerDataVO;
	import com.game.event.GameEvent;
	import com.game.manager.NotificationManager;
	import com.game.view.component.notification.TipBox;
	
	import config.Config;
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class ESShopThing extends Sprite
	{
		
		public function ESShopThing()
		{
			super();
			TextUtil.redrawTxtOld(this, ["txt_name", "txt_price"]);
			this.curObj = {};
			this.gc = Config.getIns();
			this.addEventListener(Event.ADDED_TO_STAGE, this.added, false, 0, true);
			this.addEventListener(Event.REMOVED_FROM_STAGE, this.removed, false, 0, true);
		}
		
		public var btn_buy:SimpleButton;
		
		public var txt_name:TextField;
		
		public var txt_price:TextField;
		private var gc:Config;
		private var curObj:Object;
		private var player:PlayerDataVO;
		
		public function setEquipment(param1:Object):void
		{
			this.curObj = param1;
			this.txt_name.text = param1.cname + " ";
			this.txt_price.text = param1.score + "积分";
		}
		
		public function setScore(param1:int):void
		{
			this.curObj.score = param1;
			this.txt_price.text = param1 + "积分";
		}
		
		public function setImg(param1:String):void
		{
			this.curObj.img = param1;
			var _loc3_:Sprite = ResUtil.getImageSprite(param1);
			_loc3_.name = "score_show_image";
			_loc3_.x = 15;
			_loc3_.y = 20;
			this.addChild(_loc3_);
		}
		
		public function clearEquipment():void
		{
			if (this.getChildByName("score_show_image") != null)
			{
				this.removeChild(this.getChildByName("score_show_image"));
			}
		}
		
		public function setPlayer(param1:PlayerDataVO):void
		{
			this.player = param1;
		}
		
		private function exchangeFinish():void
		{
			var _loc4_:* = undefined;
			trace("this.curObj.img -->>" + this.curObj.img);
			var _loc1_:Array = String(this.curObj.img).split("_");
			if (_loc1_[1] == "exp")
			{
				return;
			}
			if (_loc1_[1] == "cw")
			{
				if (this.player.petList.length >= ConfigConst.GAME_PET_MAX_SEAT)
				{
					NotificationManager.alert("玩家宠物栏已满!");
					return;
				}
				this.cwExchange(_loc1_[2]);
			}
			else if ((_loc4_ = this.gc.allEquip.findByName(_loc1_[1])) != null)
			{
				trace("temp.type -->>" + _loc4_.type);
				if (_loc4_.type == "zbwp" || _loc4_.type == "wpqhs")
				{
					this.gc.putQhsInBackPack(this.player, _loc1_[1], int(_loc1_[2]));
				}
				else if (_loc4_.type == "zbsz")
				{
					this.player.bugConsumeList.push(_loc4_);
				}
				else if (_loc4_.equipId == "qljfb")
				{
					_loc4_.setEupdata(Number((1.6 + Math.random() * 0.8).toFixed(1)));
					_loc4_.setWX(true, true, true, true, true);
					this.player.bagEquipList.push(_loc4_);
				}
				else if (_loc4_.equipId == "mdhf")
				{
					_loc4_.setWX(true, true, true, true, true);
					this.player.bagEquipList.push(_loc4_);
				}
				else if (_loc4_.equipId == "jyhl")
				{
					_loc4_.setWX(true, true, true, true, true);
					this.player.bagEquipList.push(_loc4_);
				}
				else if (_loc4_.equipId == "stlp")
				{
					this.player.bagEquipList.push(_loc4_);
				}
			}
			NotificationManager.alert("兑换成功");
			this.gc.userData.turnTableScore -= this.curObj.score;
			this.gc.eventManager.dispatchEvent(new GameEvent("ExchangeShopSuccess"));
		}
		
		private function cwExchange(param1:String):void
		{
			var _loc2_:PetDataVO = new PetDataVO();
			if (param1 == "huwan")
			{
				_loc2_.setPetNameAndLevel("tigress1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(1300);
				_loc2_.setmpQuality(1040);
				_loc2_.setatkQuality(1300);
				_loc2_.setdefQuality(520);
				_loc2_.setHp(500);
				_loc2_.setMp(150);
				_loc2_.setAtk(30);
				_loc2_.setDef(8);
			}
			else if (param1 == "guibu")
			{
				_loc2_.setPetNameAndLevel("turtle1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(1560);
				_loc2_.setmpQuality(910);
				_loc2_.setatkQuality(1170);
				_loc2_.setdefQuality(611);
				_loc2_.setHp(600);
				_loc2_.setMp(150);
				_loc2_.setAtk(25);
				_loc2_.setDef(10);
			}
			else if (param1 == "quedan")
			{
				_loc2_.setPetNameAndLevel("phoenix1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(1170);
				_loc2_.setmpQuality(1170);
				_loc2_.setatkQuality(1300);
				_loc2_.setdefQuality(520);
				_loc2_.setHp(450);
				_loc2_.setMp(200);
				_loc2_.setAtk(32);
				_loc2_.setDef(6);
			}
			else if (param1 == "huowan")
			{
				_loc2_.setPetNameAndLevel("monkey1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(1040);
				_loc2_.setmpQuality(1040);
				_loc2_.setatkQuality(1040);
				_loc2_.setdefQuality(520);
				_loc2_.setHp(200);
				_loc2_.setMp(150);
				_loc2_.setAtk(20);
				_loc2_.setDef(6);
			}
			else if (param1 == "xueqiu")
			{
				_loc2_.setPetNameAndLevel("horse1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(949);
				_loc2_.setmpQuality(1222);
				_loc2_.setatkQuality(1105);
				_loc2_.setdefQuality(520);
				_loc2_.setHp(150);
				_loc2_.setMp(250);
				_loc2_.setAtk(25);
				_loc2_.setDef(6);
			}
			else if (param1 == "longzai")
			{
				_loc2_.setPetNameAndLevel("dragon1", 1);
				_loc2_.setperception(7);
				_loc2_.setwarpower(8);
				_loc2_.settechnique(8);
				_loc2_.sethpQuality(1400);
				_loc2_.setmpQuality(700);
				_loc2_.setatkQuality(1400);
				_loc2_.setdefQuality(500);
				_loc2_.setHp(300);
				_loc2_.setMp(175);
				_loc2_.setAtk(25);
				_loc2_.setDef(5);
			}
			else if (param1 == "zishu")
			{
				_loc2_.setPetNameAndLevel("mouse1", 1);
				_loc2_.setperception(3 + Math.ceil(Math.random() * 4));
				_loc2_.setwarpower(4 + Math.ceil(Math.random() * 4));
				_loc2_.settechnique(4 + Math.ceil(Math.random() * 4));
				_loc2_.sethpQuality(1300 + Math.ceil(Math.random() * 350));
				_loc2_.setmpQuality(200 + Math.ceil(Math.random() * 50));
				_loc2_.setatkQuality(1200 + Math.ceil(Math.random() * 350));
				_loc2_.setdefQuality(200 + Math.ceil(Math.random() * 100));
				_loc2_.setHp(450);
				_loc2_.setMp(200);
				_loc2_.setAtk(32);
				_loc2_.setDef(6);
			}
			_loc2_.setSHp(_loc2_.getHp());
			_loc2_.setSMp(_loc2_.getMp());
			this.player.petList.push(_loc2_);
		}
		
		private function added(param1:Event):void
		{
			this.btn_buy.addEventListener(MouseEvent.CLICK, this.buyClick);
		}
		
		private function removed(param1:Event):void
		{
			this.btn_buy.removeEventListener(MouseEvent.CLICK, this.buyClick);
		}
		
		private function buyClick(param1:MouseEvent):void
		{
			if (this.player == null)
			{
				NotificationManager.alert("请选择要购买的角色");
				return;
			}
			var _loc1_:TipBox = new TipBox("您确定要花费" + this.curObj.score + "点积分购买所选商品?", this.buyConfirm);
			_loc1_.add();
		}
		
		private function buyConfirm(param1:MouseEvent):void
		{
			if (isNaN(this.gc.userData.turnTableScore) || isNaN(this.curObj.score))
			{
				NotificationManager.alert("非法数据！");
				return;
			}
			if (this.gc.userData.turnTableScore < this.curObj.score)
			{
				NotificationManager.alert("积分不足");
				
			}
			else
			{
				this.exchangeFinish();
			}
		}
	}
}
